jQuery(document).ready(function () {
    selectList();
    $("#resetBtn").on("click",function () {
        $("#projectName").val("");
        $("#projectId").val("");
        $("#state").val("");
        $("#startTime").val("");
        $("#endTime").val("");
    })
});
function queryParams(params) {
    return getQueryParams(params, "searchForm");
}
function selectList(){
    $('#projectTable').bootstrapTable("destroy");
    $('#projectTable').bootstrapTable({
        method: "post",
        url: rootPath+"/projectCon/ajax/getProjectList",
        showExport : true,
        exportTypes: ['excel'],//['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
        Icons:'glyphicon-export',
        exportOptions:{
            ignoreColumn: [0],  //忽略某一列的索引
            fileName: '项目列表',  //文件名称设置
            worksheetName: 'sheet1',  //表格工作区名称
            tableName: '项目列表'
        },
        exportDataType : 'all'
    });
}
function proInfoFormatter(value,row,index) {
    return '<a onclick="javascript:commonJs.alertMsg('+"\'"+row.pro_describe+"\'"+');">'+value+'</a>';
}
function addProject() {
        layer.open({
            type: 2,
            title: "添加项目",
            shadeClose: false,
            shade: 0.8,
            area: ['70%', '75%'],
            content: rootPath + "/projectCon/toPage/addProjectView?decorator=decorator_blank",
            maxmin: true
        });
}
function updProjectInfo() {
    var selections = $('#projectTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state !='未启动'){
        layer.alert("此项目非“未启动”状态，不可执行修改操作！");
        return;
    }
    layer.open({
        type: 2,
        title: "修改项目信息",
        shadeClose: false,
        shade: 0.8,
        area: ['70%', '75%'],
        content: rootPath + "/projectCon/toPage/updProjectView?decorator=decorator_blank&proId="+selections[0].pro_id,
        maxmin: true
    });
}
function doStart() {
    var selections = $('#projectTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state !='未启动'){
        layer.alert("此项目非“未启动”状态，不可执行启动操作！");
        return;
    }
    var proId = selections[0].pro_id;
    layer.open({
        content: '确定启动此项目?（启动后将无法修改相关信息！）',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/projectCon/ajax/doStart",
                data:{proId:proId},
                dataType: "json",
                success : function(data) {
                    $("#projectTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("启动出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}
function addProjectFund() {
    var selections = $('#projectTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state !='已启动'){
        layer.alert("此状态下的项目不可增加配额！");
        return;
    }
    var proId = selections[0].pro_id;
    layer.prompt({title:"请填入预增加的配额金额(/元)：", formType: 3}, function(text, index){
        commonJs.ajaxRequest(rootPath+"/projectCon/ajax/addProjectFund",{
            proId:proId,
            addMoney:text
        },function(data){
            if(data.code == '0000'){
                commonJs.alertMsg("操作成功",function(){
                    $("#projectTable").bootstrapTable("refresh");
                    layer.close(index);
                })
            }else {
                layer.msg(data.msg);
            }
        })
    });
}
function doEnd() {
    var selections = $('#projectTable').bootstrapTable('getSelections');
    if (selections.length == 0) {
        layer.msg('请选择一行数据进行操作！', function () {
        });
        return;
    }
    if(selections[0].state !='未启动'&&selections[0].state !='已启动'){
        layer.alert("此状态下的项目不可执行废止操作！");
        return;
    }
    var proId = selections[0].pro_id;
    layer.open({
        content: '确定废止此项目?',
        btn: ['确定', "取消"],
        shade: false,
        offset: '200px',
        yes: function (index, layero) {
            $.ajax({
                type: "POST",
                url: rootPath + "/projectCon/ajax/doEnd",
                data:{proId:proId},
                dataType: "json",
                success : function(data) {
                    $("#projectTable").bootstrapTable('refresh');//刷新表格
                    if(data.code == '0000') {
                        layer.msg(data.msg, {icon: 1});
                    }else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                error:function(){
                    layer.msg("操作出错！",{icon: 2});
                }
            });
        },
        cancel: function (index) {
        }
    });
}